//
//  LJVC.m
//  SYPerfectDemo
//
//  Created by Lssyyy on 2018/10/14.
//  Copyright © 2018年 Lssyyy. All rights reserved.
//

#import "ImageFilterVC.h"
#import "MBProgressHUD.h"
@interface ImageFilterVC ()
@property (nonatomic,strong) UIImageView *imageView;
@property (nonatomic,strong) UIImageView *filterImageView;
@end

@implementation ImageFilterVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)addUI{
    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth/2, kScreenWidth)];
    self.imageView.image = [UIImage imageNamed:@"image_ticket_get_nothing"];
    [self.view addSubview:self.imageView];
    
    self.filterImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth/2 + 1, 0, kScreenWidth/2-1, kScreenWidth)];
    self.filterImageView.image = [UIImage imageNamed:@"image_ticket_get_nothing"];
    [self.view addSubview:self.filterImageView];
    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    CIImage *inputImage = [CIImage imageWithCGImage:_filterImageView.image.CGImage];
    CIFilter *filter =[CIFilter filterWithName:@"CIColorMonochrome"];
    NSLog(@"%@",filter.attributes);
    
     NSLog(@"分割%@",[CIFilter filterNamesInCategory:kCICategoryColorEffect]);
    [filter setValue:inputImage forKey:kCIInputImageKey];
    [filter setValue:[CIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1] forKey:kCIInputColorKey];
    
    CIImage *outputImage =filter.outputImage;
    
    CIContext *context =[CIContext contextWithOptions:nil];
    
    CGImageRef imageRef = [context createCGImage:outputImage fromRect:outputImage.extent];
    
    _filterImageView.image =[UIImage imageWithCGImage:imageRef];
    
    [hud hideAnimated:YES];
}

- (void)dealloc{
   NSLog(@"计数：%lu",[_imageView arcDebugRetainCount]);
    
}

@end
